<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class OrderRefund extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('order_refund');
        if(!$exists){
        $table = $this->table('order_refund', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci', 'comment' => '订单退款' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
        $table->addColumn('refund_no', 'string', ['limit' => 20,'null' => false,'default' => null,'signed' => true,'comment' => '退款单号',])
			->addColumn('refund_reason', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '退款原因',])
			->addColumn('refund_type', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '物流类型：0 未收到货、1已收到货',])
			->addColumn('refund_express', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '退款物流名称',])
			->addColumn('refund_express_no', 'string', ['limit' => 20,'null' => true,'signed' => true,'comment' => '退款物流单号',])
			->addColumn('refund_price', 'decimal', ['precision' => 10,'scale' => 2,'null' => false,'default' => 0,'signed' => true,'comment' => '退款金额',])
			->addColumn('order_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => true,'comment' => '订单ID',])
			->addColumn('status', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '状态：0 处理中、1 已完成、2 失败',])
			->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '创建时间',])
			->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '更新时间',])
            ->create();
        }
    }
}
